home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
gsdbloo.exe
/
DEMOTV01.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-02-24
|
6KB
|
224 lines
program DEMOTV01;
{------------------------------------------------------------------------------
DBase File Display
TurboVision Sample 1
Demo Program
Copyright (c) Richard F. Griffin
24 February 1992
102 Molded Stone Pl
Warner Robins, GA 31088
-------------------------------------------------------------
This program demonstrates that the basic Griffin Solutions
routines will work in a TurboVision environment. This demo
modifies one of the TP 6 TurboVision documentation programs
to use a dBase file.
Memory is at a premium in the IDE using TurboVision. For
this reason, Debug information is turned off in all of the
Griffin Solutions Units ($D-). If you get heap overflow errors
or 'strange' things happen, if probably means there is not
enough memory to run in the IDE. To regain memory, you can
compile to disk instead of memory. Use the MemAvail value in
the Watch window to see how much memory is available.
-------------------------------------------------------------------------------}
uses
GS_dBase,
GS_dBFld,
GS_FileH,
GS_GenF,
Objects, Drivers, Views, Menus, App;
const
MaxLines = 100;
WinCount: Integer = 0;
cmFileOpen = 100;
cmNewWin = 101;
var
LineCount: Integer;
Lines: array[0..MaxLines - 1] of PString;
type
TMyApp = object(TApplication)
procedure HandleEvent(var Event: TEvent); virtual;
procedure InitMenuBar; virtual;
procedure InitStatusLine; virtual;
procedure NewWindow;
end;
PInterior = ^TInterior;
TInterior = object(TScroller)
constructor Init(var Bounds: TRect; AHScrollBar,
AVScrollBar: PScrollBar);
procedure Draw; virtual;
end;
PDemoWindow = ^TDemoWindow;
TDemoWindow = object(TWindow)
constructor Init(Bounds: TRect; WinTitle: String; WindowNo: Word);
procedure MakeInterior(Bounds: TRect);
end;
procedure ReadFile;
var
dBFile : GS_dBFld_Objt;
CkFile : file;
s : string;
begin
if not GS_FileExists(CkFile,'DEMOTV1.DBF') then
MakeTestData('DEMOTV1', 20, false);
dBFile.Init('DEMOTV1');
dBFile.Open;
dBFile.GetRec(Top_Record);
LineCount := 0;
while not dBFile.File_EOF and (LineCount < MaxLines) do
begin
s := dBFile.FieldGet('LASTNAME') + dBFile.FieldGet('FIRSTNAME');
Lines[LineCount] := NewStr(S);
inc(LineCount);
dBFile.GetRec(Next_Record); {Get the next sequential record}
end;
dBFile.Close; {Close the dBase III file}
end;
procedure DoneFile;
var
I: Integer;
begin
for I := 0 to LineCount - 1 do
if Lines[I] <> nil then DisposeStr(Lines[i]);
end;
{ TInterior }
constructor TInterior.Init(var Bounds: TRect; AHScrollBar,
AVScrollBar: PScrollBar);
begin
TScroller.Init(Bounds, AHScrollBar, AVScrollBar);
GrowMode := gfGrowHiX + gfGrowHiY;
Options := Options or ofFramed;
SetLimit(128, LineCount);
end;
procedure TInterior.Draw;
var
Color: Byte;
I, Y: Integer;
B: TDrawBuffer;
begin
Color := GetColor(1);
for Y := 0 to Size.Y - 1 do
begin
MoveChar(B, ' ', Color, Size.X);
i := Delta.Y + Y;
if (I < LineCount) and (Lines[I] <> nil) then
MoveStr(B, Copy(Lines[I]^, Delta.X + 1, Size.X), Color);
WriteLine(0, Y, Size.X, 1, B);
end;
end;
{ TDemoWindow }
constructor TDemoWindow.Init(Bounds: TRect; WinTitle: String;
WindowNo: Word);
var
S: string[3];
begin
Str(WindowNo, S);
TWindow.Init(Bounds, WinTitle + ' ' + S, wnNoNumber);
MakeInterior(Bounds);
end;
procedure TDemoWindow.MakeInterior(Bounds: TRect);
var
HScrollBar, VScrollBar: PScrollBar;
Interior: PInterior;
R: TRect;
begin
VScrollBar := StandardScrollBar(sbVertical + sbHandleKeyboard);
HScrollBar := StandardScrollBar(sbHorizontal + sbHandleKeyboard);
GetExtent(Bounds);
Bounds.Grow(-1,-1);
Interior := New(PInterior, Init(Bounds, HScrollBar, VScrollBar));
Insert(Interior);
end;
{ TMyApp }
procedure TMyApp.HandleEvent(var Event: TEvent);
begin
TApplication.HandleEvent(Event);
if Event.What = evCommand then
begin
case Event.Command of
cmNewWin: NewWindow;
else
Exit;
end;
ClearEvent(Event);
end;
end;
procedure TMyApp.InitMenuBar;
var R: TRect;
begin
GetExtent(R);
R.B.Y := R.A.Y + 1;
MenuBar := New(PMenuBar, Init(R, NewMenu(
NewSubMenu('~F~ile', hcNoContext, NewMenu(
NewItem('~O~pen', 'F3', kbF3, cmFileOpen, hcNoContext,
NewItem('~N~ew', 'F4', kbF4, cmNewWin, hcNoContext,
NewLine(
NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoContext,
nil))))),
NewSubMenu('~W~indow', hcNoContext, NewMenu(
NewItem('~N~ext', 'F6', kbF6, cmNext, hcNoContext,
NewItem('~Z~oom', 'F5', kbF5, cmZoom, hcNoContext,
nil))),
nil))
)));
end;
procedure TMyApp.InitStatusLine;
var R: TRect;
begin
GetExtent(R);
R.A.Y := R.B.Y - 1;
StatusLine := New(PStatusLine, Init(R,
NewStatusDef(0, $FFFF,
NewStatusKey('', kbF10, cmMenu,
NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
NewStatusKey('~F4~ New', kbF4, cmNewWin,
NewStatusKey('~Alt-F3~ Close', kbAltF3, cmClose,
nil)))),
nil)
));
end;
procedure TMyApp.NewWindow;
var
Window: PDemoWindow;
R: TRect;
begin
Inc(WinCount);
R.Assign(0, 0, 50, 15);
R.Move(Random(29), Random(8));
Window := New(PDemoWindow, Init(R, 'Demo Window', WinCount));
DeskTop^.Insert(Window);
end;
var
MyApp: TMyApp;
begin
ReadFile;
MyApp.Init;
MyApp.Run;
MyApp.Done;
DoneFile;
end.